﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Controls_ProdutcDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string product_ID = Request.QueryString["Product_ID"];

            if (!string.IsNullOrEmpty(product_ID))
            {
                datalistDetail.DataSource = Product_Session.Get_ProductAsTable("Pro_ID=" + product_ID, "");
                datalistDetail.DataBind();
                /*
                if (!string.IsNullOrEmpty(Request.QueryString["Cate_ID"]))
                {
                    DataList2.DataSource = Product_Session.Get_ProductAsPaging(1, 6, "Pro_ID DESC", "*", "Cate_ID=" + Request.QueryString["Cate_ID"] + "AND Pro_ID<>" + product_ID, "");
                    DataList2.DataBind();
                }
                else
                {
                    DataList2.DataSource = Product_Session.Get_ProductAsPaging(1, 6, "Pro_ID DESC", "*", "Pro_ID<>" + product_ID, "");
                    DataList2.DataBind();
                }
                 */
                dtlComments.DataSource = Comments_session.Get_CommentsAsTable("Comments.Pro_ID=" + Request.QueryString["Product_ID"], "Com_ID DESC");
                dtlComments.DataBind(); // can phia them nguoi dang vao nua it nua lam
            }
        }

    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (Session["User_ID"] != null)
        {
            Comments comment = new Comments();
            comment.Pro_ID = int.Parse(Request.QueryString["Product_ID"]);
            comment.Com_Desc = TextAreaContent.Text;
            comment.Com_Title = txtTitle.Text;
            comment.Com_Status = true;
            comment.User_ID = int.Parse(Session["User_ID"].ToString());

            Comments_session.Insert_Comments(comment);
            dtlComments.DataSource = Comments_session.Get_CommentsAsTable("Comments.Pro_ID=" + Request.QueryString["Product_ID"], "Com_ID DESC");
            dtlComments.DataBind(); // can phia them nguoi dang vao nua it nua lam
            txtTitle.Text = TextAreaContent.Text = "";
        }
        else
        {
            WebMsgBox.Show("Bạn phải đang nhập thì mới comment được");
            txtTitle.Text = TextAreaContent.Text = "";
        }
    }
    
}
